Let Ladda return the same object references - immutable cache #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A current pain point with Ladda IMO is that every cache hit gives you a new reference to a cached object. While this is super-safe and makes it impossible to destroy the cache through mutation, it's also a strange contract - especially given current practices around dealing with immutable objects in e.g. React.
The issue is resolved here.
For backwards compatibility there's a global flag called
strictwhich defaults totrue. It performs an Object.freeze on cache objects, so that we can still guarantee that our cache is not unlawfully manipulated.However, some past users might have violated this rule in the past -
strict: falsewould keep their code alive at least.In addition the flag can be set to false when you just don't want these safeties - we deep freeze everything. Not sure how freeze performs - probably quite quick - still, adds some overhead.
This was done a while ago already - I think it's time to merge it.
On the branch
fix/id-from-args-with-listsI just pushed a seemingly unrelated broken test I discovered earlier. This test would also be fixed by the changes made in this PR.cc @mlent